
import com.wider.foundation.DLogger;
import com.wider.foundation.DLoggerRoot;
import com.wider.foundation.LRURingMap;
import com.wider.foundation.models.NxFileTreeNode;
import com.wider.foundation.ui.JTextPrintStream;
import java.awt.Image;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.activation.MimetypesFileTypeMap;
import javax.imageio.ImageIO;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HttpFileCommander.java
 *
 * Created on 2010-8-28, 1:13:14
 */

/**
 *
 * @author William
 */
public class HttpFileCommander extends javax.swing.JFrame{

    /** Creates new form HttpFileCommander */
    public HttpFileCommander() {
        try {
            Preparation();
            initComponents();
            UserInit();
            JFileChooser fc = new JFileChooser();
            rootlog.debug(fc.getTypeDescription(new File("resources/Vienna 教吹 HD.mp4")));
        } catch (IOException ex) {
            Logger.getLogger(HttpFileCommander.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        jPopupMenu1 = new javax.swing.JPopupMenu();
        jSplitPane4 = new javax.swing.JSplitPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jSplitPane5 = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton_closeThisTab = new javax.swing.JButton();
        jButton_closeAllTabs = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jButton_newTab = new javax.swing.JButton();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel_LocalHost = new javax.swing.JPanel();
        jButton_newLocalDir = new javax.swing.JButton();
        jCombo_selDrive = new javax.swing.JComboBox();
        jButton_delLocal = new javax.swing.JButton();
        jButton_uploade = new javax.swing.JButton();
        jSplitPane2 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree_Local = new javax.swing.JTree();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTableFile_Local = new javax.swing.JTable();
        jTabbedPane_Remotes = new javax.swing.JTabbedPane();
        jPanel_Remote = new javax.swing.JPanel();
        jButton_delRemote = new javax.swing.JButton();
        jButton_newRemoteDir = new javax.swing.JButton();
        jButton_download = new javax.swing.JButton();
        jSplitPane3 = new javax.swing.JSplitPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTree_Remote = new javax.swing.JTree();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTableFile_Remote = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jButton_addHost = new javax.swing.JButton();
        jButton_connect = new javax.swing.JButton();
        jCombo_URL = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        LogMessagePane = new javax.swing.JTextPane();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jSplitPane4.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jSplitPane4.setDividerLocation(520);
        jSplitPane4.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(jTable1);

        jSplitPane4.setRightComponent(jScrollPane3);

        jSplitPane5.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jSplitPane5.setDividerLocation(120);
        jSplitPane5.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        jLabel1.setFont(new java.awt.Font("新細明體", 1, 12));
        jLabel1.setText("Local");

        jButton_closeThisTab.setText("this tab");
        jButton_closeThisTab.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_closeThisTabActionPerformed(evt);
            }
        });

        jButton_closeAllTabs.setText("all tabs");
        jButton_closeAllTabs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_closeAllTabsActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("新細明體", 1, 12));
        jLabel5.setText("Close:");

        jButton_newTab.setText("New Tab");
        jButton_newTab.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_newTabActionPerformed(evt);
            }
        });

        jSplitPane1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jSplitPane1.setDividerLocation(460);

        jPanel_LocalHost.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButton_newLocalDir.setText("New Folder");
        jButton_newLocalDir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_newLocalDirActionPerformed(evt);
            }
        });

        jCombo_selDrive.setModel(new DefaultComboBoxModel(File.listRoots()));
        jCombo_selDrive.setSelectedItem(jCombo_selDrive.getItemAt(0));
        jCombo_selDrive.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCombo_selDriveActionPerformed(evt);
            }
        });

        jButton_delLocal.setText("Delete");

        jButton_uploade.setText("Upload >>");

        jSplitPane2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jSplitPane2.setDividerLocation(99);

        jTree_Local.setToggleClickCount(1);
        jTree_Local.addTreeExpansionListener(new javax.swing.event.TreeExpansionListener() {
            public void treeCollapsed(javax.swing.event.TreeExpansionEvent evt) {
            }
            public void treeExpanded(javax.swing.event.TreeExpansionEvent evt) {
                jTree_LocalTreeExpanded(evt);
            }
        });
        jTree_Local.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                jTree_LocalValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jTree_Local);

        jSplitPane2.setLeftComponent(jScrollPane1);

        jTableFile_Local.setAutoCreateRowSorter(true);
        jTableFile_Local.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Name", "Size", "Type", "Date"
            }
        ));
        jTableFile_Local.setGridColor(new java.awt.Color(237, 252, 255));
        jTableFile_Local.setRowHeight(18);
        jTableFile_Local.setSelectionBackground(new java.awt.Color(193, 238, 255));
        jTableFile_Local.setSelectionForeground(new java.awt.Color(0, 0, 0));
        jTableFile_Local.setShowVerticalLines(false);
        jScrollPane5.setViewportView(jTableFile_Local);

        jSplitPane2.setRightComponent(jScrollPane5);

        javax.swing.GroupLayout jPanel_LocalHostLayout = new javax.swing.GroupLayout(jPanel_LocalHost);
        jPanel_LocalHost.setLayout(jPanel_LocalHostLayout);
        jPanel_LocalHostLayout.setHorizontalGroup(
            jPanel_LocalHostLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_LocalHostLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel_LocalHostLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE)
                    .addGroup(jPanel_LocalHostLayout.createSequentialGroup()
                        .addComponent(jButton_newLocalDir, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton_delLocal, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton_uploade, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE))
                    .addComponent(jCombo_selDrive, javax.swing.GroupLayout.Alignment.TRAILING, 0, 435, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel_LocalHostLayout.setVerticalGroup(
            jPanel_LocalHostLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_LocalHostLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jCombo_selDrive, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel_LocalHostLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_newLocalDir)
                    .addComponent(jButton_delLocal)
                    .addComponent(jButton_uploade))
                .addContainerGap())
        );

        jSplitPane1.setLeftComponent(jPanel_LocalHost);

        jTabbedPane_Remotes.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jTabbedPane_RemotesStateChanged(evt);
            }
        });

        jButton_delRemote.setText("Delete");

        jButton_newRemoteDir.setText("New Folder");
        jButton_newRemoteDir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_newRemoteDirActionPerformed(evt);
            }
        });

        jButton_download.setText("<< download");

        jSplitPane3.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jSplitPane3.setDividerLocation(99);

        jScrollPane2.setViewportView(jTree_Remote);

        jSplitPane3.setLeftComponent(jScrollPane2);

        jTableFile_Remote.setAutoCreateRowSorter(true);
        jTableFile_Remote.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Name", "Size", "Type", "Date"
            }
        ));
        jTableFile_Remote.setGridColor(new java.awt.Color(237, 252, 255));
        jTableFile_Remote.setRowHeight(18);
        jTableFile_Remote.setSelectionBackground(new java.awt.Color(193, 238, 255));
        jTableFile_Remote.setSelectionForeground(new java.awt.Color(0, 0, 0));
        jTableFile_Remote.setShowVerticalLines(false);
        jScrollPane6.setViewportView(jTableFile_Remote);

        jSplitPane3.setRightComponent(jScrollPane6);

        jLabel2.setText("Remote URL");

        jButton_addHost.setText("Keep");
        jButton_addHost.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_addHostActionPerformed(evt);
            }
        });

        jButton_connect.setText("Go");
        jButton_connect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_connectActionPerformed(evt);
            }
        });

        jCombo_URL.setEditable(true);
        jCombo_URL.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jCombo_URL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCombo_URLActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel_RemoteLayout = new javax.swing.GroupLayout(jPanel_Remote);
        jPanel_Remote.setLayout(jPanel_RemoteLayout);
        jPanel_RemoteLayout.setHorizontalGroup(
            jPanel_RemoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel_RemoteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel_RemoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSplitPane3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 616, Short.MAX_VALUE)
                    .addGroup(jPanel_RemoteLayout.createSequentialGroup()
                        .addComponent(jButton_download, javax.swing.GroupLayout.DEFAULT_SIZE, 436, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton_newRemoteDir)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton_delRemote, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel_RemoteLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCombo_URL, 0, 424, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton_connect, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_addHost, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel_RemoteLayout.setVerticalGroup(
            jPanel_RemoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel_RemoteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel_RemoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jButton_addHost, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton_connect, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jCombo_URL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel_RemoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_delRemote)
                    .addComponent(jButton_newRemoteDir)
                    .addComponent(jButton_download))
                .addContainerGap())
        );

        jTabbedPane_Remotes.addTab("tab1", jPanel_Remote);

        jSplitPane1.setRightComponent(jTabbedPane_Remotes);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 822, Short.MAX_VALUE)
                .addComponent(jButton_newTab)
                .addGap(18, 18, 18)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton_closeAllTabs)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_closeThisTab))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jButton_closeThisTab)
                    .addComponent(jButton_closeAllTabs)
                    .addComponent(jLabel5)
                    .addComponent(jButton_newTab))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE)
                .addContainerGap())
        );

        jSplitPane5.setBottomComponent(jPanel1);

        jLabel3.setFont(new java.awt.Font("新細明體", 1, 12));
        jLabel3.setText("Console");

        jScrollPane4.setViewportView(LogMessagePane);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel4.setText("FileJilla v0.1 Copyright(c) wacau.net");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 849, Short.MAX_VALUE)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 1117, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
        );

        jSplitPane5.setLeftComponent(jPanel2);

        jSplitPane4.setLeftComponent(jSplitPane5);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane4)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 774, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_newLocalDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_newLocalDirActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton_newLocalDirActionPerformed

    private void jButton_closeAllTabsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_closeAllTabsActionPerformed
        // TODO add your handling code here:
        jTabbedPane_Remotes.removeAll();
    }//GEN-LAST:event_jButton_closeAllTabsActionPerformed

    private void jButton_addHostActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_addHostActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jButton_addHostActionPerformed

    private void jButton_newRemoteDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_newRemoteDirActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jButton_newRemoteDirActionPerformed

    private void jButton_connectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_connectActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jButton_connectActionPerformed

    private void jTabbedPane_RemotesStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jTabbedPane_RemotesStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jTabbedPane_RemotesStateChanged

    private void jButton_newTabActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_newTabActionPerformed
        // TODO add your handling code here:
        jTabbedPane_Remotes.addTab("new" + jTabbedPane_Remotes.getTabCount(), new JPanel());
        jTabbedPane_Remotes.setSelectedIndex(jTabbedPane_Remotes.getTabCount() - 1);
    }//GEN-LAST:event_jButton_newTabActionPerformed

    private void jButton_closeThisTabActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_closeThisTabActionPerformed
        // TODO add your handling code here:
        jTabbedPane_Remotes.remove(jTabbedPane_Remotes.getSelectedIndex());
    }//GEN-LAST:event_jButton_closeThisTabActionPerformed

    private void jCombo_selDriveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCombo_selDriveActionPerformed
        // TODO add your handling code here:
        Object selectedDrive = jCombo_selDrive.getSelectedItem();

        if (null == selectedDrive)
            return;
        if (!(selectedDrive instanceof File))
            return;

        DefaultTreeModel jTreeModel = jTreeModels_Local.get((File) selectedDrive);
        if (null == jTreeModel){
            NxFileTreeNode root = new NxFileTreeNode((File) selectedDrive);
            jTreeModel = new DefaultTreeModel(root);
            jTreeModels_Local.put(((File) selectedDrive), jTreeModel);
            listFolders(root);
        }
        
        jTree_Local.setModel(jTreeModel);
        jTree_Local.updateUI();
    }//GEN-LAST:event_jCombo_selDriveActionPerformed

    private void jCombo_URLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCombo_URLActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jCombo_URLActionPerformed

    private void jTree_LocalTreeExpanded(javax.swing.event.TreeExpansionEvent evt) {//GEN-FIRST:event_jTree_LocalTreeExpanded
        // TODO add your handling code here:
        TreePath path = evt.getPath();
        NxFileTreeNode selection = (NxFileTreeNode) path.getPath()[path.getPathCount() - 1];
        if (listFolders(selection))
            ((DefaultTreeModel) jTree_Local.getModel()).nodeStructureChanged(selection);

    }//GEN-LAST:event_jTree_LocalTreeExpanded

    private void jTree_LocalValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jTree_LocalValueChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jTree_LocalValueChanged

    private void jTree_LocalModelChanged(){
        rootlog.debug("jTreeModel_Local changed!");

    }

    private boolean listFiles(NxFileTreeNode node){
        boolean ret = false;

        return ret;
    }

    private boolean listFolders(NxFileTreeNode node){
        if (null == node)
            return false;
        if (!(node.getUserObject() instanceof File))
            return false;
        if (node.getChildCount() > 0)
            return false;
        
        File curr = (File) node.getUserObject();
        File [] folders;
        folders = curr.listFiles(new FileFilter(){

            @Override
            public boolean accept(File pathname) {
                if (pathname.isDirectory() && (!pathname.getName().contains("$")))
                    return true;
                return false;
            }
        });

        if (null == folders)
            return false;
        
        NxFileTreeNode newnode = null;
        for (File folder : folders){
            newnode = new NxFileTreeNode(folder);
            newnode.setAllowsChildren(false);
            node.setAllowsChildren(true);
            node.add(newnode);
        }
        if (null != newnode)
            return true;
        return false;
    }

    private void Preparation(){
        jTreeModels_Local   = new HashMap<File, DefaultTreeModel>();
        NodeTableMap_Local  = new LRURingMap<NxFileTreeNode, DefaultTableModel>(12);
    }
    
    private void UserInit() throws IOException{
        //1) Construct the Root Logger, then enable it.
        jTextConsole = new JTextPrintStream(LogMessagePane);
        rootlog = DLogger.getRoot();
        rootlog.setStream(jTextConsole);
        rootlog.setLevel(DLogger.DLevel.DEBUG);
        rootlog.enable();

        //2) Customize the JTree
        ImageIcon folder_open   = createImageIcon("icons/folder_open.png");
        ImageIcon folder_close  = createImageIcon("icons/folder_close.png");
        DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
        renderer.setClosedIcon(folder_close);
        renderer.setOpenIcon(folder_open);
        renderer.setLeafIcon(folder_open);
        jTree_Local.setCellRenderer(renderer);

        
        //4) Sync up the JTree to the default Drive.
        jCombo_selDriveActionPerformed(null);

        //Final) Complete the User-Init.
        rootlog.debug("Completed.");
    }

    private ImageIcon createImageIcon(String path) throws IOException {
        java.net.URL imgURL =  this.getClass().getResource(path);
        if (imgURL != null) {
            return new ImageIcon(ImageIO.read(imgURL).getScaledInstance(16, 16, Image.SCALE_SMOOTH));
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(HttpFileCommander.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(HttpFileCommander.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(HttpFileCommander.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(HttpFileCommander.class.getName()).log(Level.SEVERE, null, ex);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new HttpFileCommander().setVisible(true);

            }
        });

    }

    // User defined components declaration
    private JTextPrintStream    jTextConsole;
    private JFileChooser        FileTypeChkr;
    private DLoggerRoot         rootlog;
    private HashMap<File, DefaultTreeModel>                             jTreeModels_Local;
    private LRURingMap<NxFileTreeNode, DefaultTableModel>          NodeTableMap_Local;
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextPane LogMessagePane;
    private javax.swing.JButton jButton_addHost;
    private javax.swing.JButton jButton_closeAllTabs;
    private javax.swing.JButton jButton_closeThisTab;
    private javax.swing.JButton jButton_connect;
    private javax.swing.JButton jButton_delLocal;
    private javax.swing.JButton jButton_delRemote;
    private javax.swing.JButton jButton_download;
    private javax.swing.JButton jButton_newLocalDir;
    private javax.swing.JButton jButton_newRemoteDir;
    private javax.swing.JButton jButton_newTab;
    private javax.swing.JButton jButton_uploade;
    private javax.swing.JComboBox jCombo_URL;
    private javax.swing.JComboBox jCombo_selDrive;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel_LocalHost;
    private javax.swing.JPanel jPanel_Remote;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JSplitPane jSplitPane3;
    private javax.swing.JSplitPane jSplitPane4;
    private javax.swing.JSplitPane jSplitPane5;
    private javax.swing.JTabbedPane jTabbedPane_Remotes;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTableFile_Local;
    private javax.swing.JTable jTableFile_Remote;
    private javax.swing.JTree jTree_Local;
    private javax.swing.JTree jTree_Remote;
    // End of variables declaration//GEN-END:variables

}
